// App.h

#ifndef __APP_H
#define __APP_H

#include "Ribbon.h"
#include "AppState.h"
#include "Panel.h"

#include "Common/7Zip/PropID.h"
#include "Common/Archive/CompressCall.h"
#include "HelpUtils.h"
#include "AboutDialog.h"
#include "MyLoadMenu.h"

#include "Common/System/Threading/SimpleWorkerPool.h"
#include <memory>

extern void OptionsDialog(HWND hwndOwner);

extern LPCWSTR kFMHelpTopic;


class CMainWnd;

extern CMainWnd g_App;

const int kNumPanelsMax = 2;

enum
{
	kAddCommand = kToolbarStartID,
	kExtractCommand,
	kTestCommand
};


enum ApplicationModes
{
	appModeDefault = 0,
	appModeZipTools = 1
};

class CMainWnd;

class ATL_NO_VTABLE CDropTarget:
	public IDropTarget,
	public CComObjectRootEx<CComMultiThreadModelNoCS>
{
	CComPtr<IDataObject> m_DataObject;
	CStringVector m_SourcePaths;
	int m_SelectionIndex;
	bool m_DropIsAllowed;      // = true, if data contain fillist
	int m_SubFolderIndex;
	CString m_SubFolderName;

	CPanel* m_Panel;
	bool m_IsAppTarget;        // true, if we want to drop to app window (not to panel).

	bool m_SetPathIsOK;

	bool IsItSameDrive() const;

	void QueryGetData(IDataObject* dataObject);
	bool IsFsFolderPath() const;
	DWORD GetEffect(DWORD keyState, POINTL pt, DWORD allowedEffect);
	void RemoveSelection();
	void PositionCursor(POINTL ptl);
	CString GetTargetPath() const;
	bool SetPath(bool enablePath) const;
	bool SetPath();

public:

	BEGIN_COM_MAP(CDropTarget)
	COM_INTERFACE_ENTRY(IDropTarget)
	END_COM_MAP()



	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

	STDMETHOD(DragEnter)(IDataObject* dataObject, DWORD keyState, POINTL pt, DWORD* effect);
	STDMETHOD(DragOver)(DWORD keyState, POINTL pt, DWORD* effect);
	STDMETHOD(DragLeave)();
	STDMETHOD(Drop)(IDataObject* dataObject, DWORD keyState, POINTL pt, DWORD* effect);

	CDropTarget():
		m_IsAppTarget(false),
		m_Panel(0),
		pMainWnd(0),
		m_DropIsAllowed(false),
		m_SelectionIndex(-1),
		m_SubFolderIndex(-1),
		m_SetPathIsOK(false) {}

	CMainWnd* pMainWnd;

};

class CMainWnd : public CRibbonFrameWindowImpl<CMainWnd>,
	//public CUpdateUI<CMainWnd>,
	public CMessageFilter, public CIdleHandler
{
private:
	
	Common::System::Threading::ThreadPoolPtr m_pUIWorkerPool;
public:

	DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)

	typedef CRibbonFrameWindowImpl<CMainWnd> baseFrame;

	CCommandBarCtrl m_CmdBar;

	CWindow _window;
	bool ShowSystemMenu;

	bool ShowStandardToolbar;
	bool ShowArchiveToolbar;
	bool ShowButtonsLables;
	bool LargeButtons;

	void SetToolbarText();

	CAppState AppState;
	CPanel m_wndPanel;

	//ListView drop down image
	HBITMAP m_hListViewToolbar;
	HBITMAP m_hListViewSort;

#ifdef UNDER_CE
	NWindows::NControl::CCommandBar _commandBar;
#endif

	CDropTarget* _dropTargetSpec;
	CComPtr<IDropTarget> _dropTarget;

	CMainWnd():
		_window(0), m_hListViewToolbar(NULL)
	{
		m_pUIWorkerPool = std::make_shared<Common::System::Threading::CSimpleWorkerPool>(true, 1);
	}

	void CreateDragTarget()
	{
		_dropTargetSpec = new CComObject<CDropTarget>();
		_dropTargetSpec->FinalConstruct();
		_dropTarget = _dropTargetSpec;
		_dropTargetSpec->pMainWnd = (this);
	}

	Common::System::Threading::ThreadPoolPtr* GetUIThreadPool()
	{
		return &m_pUIWorkerPool;
	}


	void DragBegin(/*int panelIndex*/)
	{
		//_dropTargetSpec->TargetPanelIndex = (NumPanels > 1) ? 1 - panelIndex : panelIndex;
		//_dropTargetSpec->SrcPanelIndex = panelIndex;
	}

	void DragEnd()
	{
		// _dropTargetSpec->TargetPanelIndex = LastFocusedPanel;
		//_dropTargetSpec->SrcPanelIndex = -1;
	}


	HRESULT CreateOnePanel(const CString &mainPath, const CString &arcFormat, bool &archiveIsOpened, bool &encrypted);
	HRESULT CreateChildren(HWND hwnd, const CString &mainPath, const CString &arcFormat, int xSize, bool &archiveIsOpened, bool &encrypted);
	void Read();
	void Save();
	void ReleaseCom();

	void SetFocusToLastItem()
	{
		m_wndPanel.SetFocusToLastRememberedItem();
	}
	CPanel &GetFocusedPanel()
	{
		return m_wndPanel;
	} //Panels[GetFocusedPanelIndex()]; }

	// File Menu
	void OpenItem()
	{
		GetFocusedPanel().OpenSelectedItems(true);
	}
	void OpenItemInside()
	{
		GetFocusedPanel().OpenFocusedItemAsInternal();
	}
	void OpenItemOutside()
	{
		GetFocusedPanel().OpenSelectedItems(false);
	}
	void EditItem()
	{
		GetFocusedPanel().EditItem();
	}
	void Rename()
	{
		GetFocusedPanel().RenameFile();
	}
	void CopyTo()
	{
		m_wndPanel.CopyItems(false, false);
	}
	void MoveTo()
	{
		m_wndPanel.CopyItems(true, false);
	}
	void Delete(bool toRecycleBin)
	{
		GetFocusedPanel().DeleteItems(toRecycleBin);
	}
	void CalculateCrc();
	void DiffFiles();
	void Properties()
	{
		GetFocusedPanel().Properties();
	}
	void Comment()
	{
		GetFocusedPanel().ChangeComment();
	}

	void MarkZipContextAvailable(bool available = true, bool active = true);

	void CreateFolder()
	{
		GetFocusedPanel().CreateFolder();
	}
	void CreateFile()
	{
		GetFocusedPanel().CreateFile();
	}

	// Edit
	void EditCut()
	{
		GetFocusedPanel().EditCut();
	}
	void EditCopy()
	{
		GetFocusedPanel().EditCopy();
	}
	void EditPaste()
	{
		GetFocusedPanel().EditPaste();
	}

	void SelectAll(bool selectMode)
	{
		GetFocusedPanel().SelectAll(selectMode);
	}
	void InvertSelection()
	{
		GetFocusedPanel().InvertSelection();
	}
	void SelectSpec(bool selectMode)
	{
		GetFocusedPanel().SelectSpec(selectMode);
	}
	void SelectByType(bool selectMode)
	{
		GetFocusedPanel().SelectByType(selectMode);
	}

	void RefreshStatusBar()
	{
		GetFocusedPanel().RefreshStatusBar();
	}

	void SetListViewMode(UINT32 index);
	UINT32 GetListViewMode()
	{
		return GetFocusedPanel().GetListViewMode();
	}
	PROPID GetSortID()
	{
		return GetFocusedPanel().GetSortID();
	}

	void SortItemsWithPropID(PROPID propID) ;

	void OpenRootFolder()
	{
		GetFocusedPanel().OpenDrivesFolder();
	}
	void OpenParentFolder()
	{
		GetFocusedPanel().OpenParentFolder();
	}
	void FoldersHistory()
	{
		GetFocusedPanel().FoldersHistory();
	}
	void RefreshView()
	{
		GetFocusedPanel().OnReload();
	}
	void RefreshAllPanels()
	{
		m_wndPanel.OnReload();
	}

	void SetListSettings();
	void SetShowSystemMenu();
	bool GetFlatMode()
	{
		return m_wndPanel.GetFlatMode();
	}
	void ChangeFlatMode()
	{
		m_wndPanel.ChangeFlatMode();
	}

	void OpenBookmark(size_t index)
	{
		m_wndPanel.OpenBookmark(index);
	}
	void SetBookmark(size_t index)
	{
		m_wndPanel.SetBookmark(index);
	}

	void ReadToolbar()
	{
		UINT32 mask = ReadToolbarsMask();
		if (mask & ((UINT32)1 << 31))
		{
			ShowButtonsLables = true;
			LargeButtons = false;
			ShowStandardToolbar = ShowArchiveToolbar = true;
		}
		else
		{
			ShowButtonsLables = ((mask & 1) != 0);
			LargeButtons = ((mask & 2) != 0);
			ShowStandardToolbar = ((mask & 4) != 0);
			ShowArchiveToolbar  = ((mask & 8) != 0);
		}
	}
	void SaveToolbar()
	{
		UINT32 mask = 0;
		if (ShowButtonsLables)
		{
			mask |= 1;
		}
		if (LargeButtons)
		{
			mask |= 2;
		}
		if (ShowStandardToolbar)
		{
			mask |= 4;
		}
		if (ShowArchiveToolbar)
		{
			mask |= 8;
		}
		SaveToolbarsMask(mask);
	}

	void SaveToolbarChanges();

	void SwitchStandardToolbar()
	{
		ShowStandardToolbar = !ShowStandardToolbar;
		SaveToolbarChanges();
	}
	void SwitchArchiveToolbar()
	{
		ShowArchiveToolbar = !ShowArchiveToolbar;
		SaveToolbarChanges();
	}
	void SwitchButtonsLables()
	{
		ShowButtonsLables = !ShowButtonsLables;
		SaveToolbarChanges();
	}
	void SwitchLargeButtons()
	{
		LargeButtons = !LargeButtons;
		SaveToolbarChanges();
	}

	void AddToArchive()
	{
		GetFocusedPanel().AddToArchive();
	}
	void ExtractArchives()
	{
		GetFocusedPanel().ExtractArchives();
	}
	void TestArchives()
	{
		GetFocusedPanel().TestArchives();
	}

	virtual bool OnNotify(UINT controlID, LPNMHDR lParam, LRESULT & /* result */);

	CString PrevTitle;
	void RefreshTitle(bool always = false);
	void RefreshTitleAlways()
	{
		RefreshTitle(true);
	}

	//amatusak
	void OnTab();
	void SetFocusToPath(int index);
	//Overrides
	HBITMAP OnRibbonQueryImage(UINT nCmdID, REFPROPERTYKEY key);
	LPCWSTR OnRibbonQueryText(UINT nCmdID, REFPROPERTYKEY key);




	void ExecuteCommand(UINT commandID);
	void SaveWindowInfo();


public :
	HWND CreateThis(/*HINSTANCE hInstance, int nCmdShow*/);

	void SetMainPath(CString path)
	{
		m_MainPath = path;
	}
	CString GetMainPath()
	{
		return m_MainPath;
	}

	void SetArcFormat(CString format)
	{
		m_ArcFormat = format;
	}
	CString GetArcFormat()
	{
		return m_ArcFormat;
	}



private:
	CString m_MainPath;
	CString m_ArcFormat;
	CString m_ToolTipBuffer;
	CString m_ToolTipBufferSys;
	static const int kNumDefaultPanels = 1;





public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual BOOL OnIdle();

	// Ribbon control map
	BEGIN_RIBBON_CONTROL_MAP(CMainWnd)
	END_RIBBON_CONTROL_MAP()

	BEGIN_UPDATE_UI_MAP(CMainWnd)
	UPDATE_ELEMENT(ID_VIEW_TOOLBAR, UPDUI_MENUPOPUP)
	UPDATE_ELEMENT(ID_VIEW_STATUS_BAR, UPDUI_MENUPOPUP)
	END_UPDATE_UI_MAP()

	BEGIN_MSG_MAP(CMainWnd)
	MESSAGE_HANDLER(WM_CREATE, OnCreate)
	MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
	MESSAGE_HANDLER(WM_INITMENUPOPUP, OnMenuPopup)
	MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)

	COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
	COMMAND_ID_HANDLER(ID_VIEW_TOOLBAR, OnViewToolBar)
	COMMAND_ID_HANDLER(ID_VIEW_STATUS_BAR, OnViewStatusBar)
	//from App
	COMMAND_ID_HANDLER(IDM_FILE_OPEN, OnFileOpen)
	COMMAND_ID_HANDLER(IDM_FILE_OPEN_INSIDE, OnFileOpenInside)
	COMMAND_ID_HANDLER(IDM_FILE_OPEN_OUTSIDE, OnFileOpenOutside)
	COMMAND_ID_HANDLER(IDM_FILE_EDIT, OnFileEditItem)
	COMMAND_ID_HANDLER(IDM_RENAME, OnFileRename)
	COMMAND_ID_HANDLER(IDM_COPY_TO, OnFileCopyTo)
	COMMAND_ID_HANDLER(IDM_MOVE_TO, OnFileMoveTo)
	COMMAND_ID_HANDLER(IDM_DELETE, OnFileDelete)
	COMMAND_ID_HANDLER(IDM_FILE_CRC, OnFileCalculateCrc)
	COMMAND_ID_HANDLER(IDM_FILE_DIFF, OnFileDiff)
	COMMAND_ID_HANDLER(IDM_FILE_SPLIT, OnFileSplit)

	COMMAND_ID_HANDLER(IDM_FILE_COMBINE, OnFileCombine)
	COMMAND_ID_HANDLER(IDM_FILE_PROPERTIES, OnFileProperties)
	COMMAND_ID_HANDLER(IDM_FILE_COMMENT, OnFileComment)
	COMMAND_ID_HANDLER(IDM_CREATE_FOLDER, OnFileCreateFolder)
	COMMAND_ID_HANDLER(IDM_CREATE_FILE, OnFileCreateFile)

	COMMAND_ID_HANDLER(IDM_EDIT_CUT, OnEditCut)
	COMMAND_ID_HANDLER(IDM_EDIT_COPY, OnEditCopy)
	COMMAND_ID_HANDLER(IDM_EDIT_PASTE, OnEditPaste)
	COMMAND_ID_HANDLER(IDM_SELECT_ALL, OnEditSelectAll)
	COMMAND_ID_HANDLER(IDM_DESELECT_ALL, OnEditDeselectAll)
	COMMAND_ID_HANDLER(IDM_INVERT_SELECTION, OnEditInvertSelection)
	COMMAND_ID_HANDLER(IDM_SELECT, OnEditSelectSpec)
	COMMAND_ID_HANDLER(IDM_SELECT_BY_TYPE, OnEditSelectByType)
	COMMAND_ID_HANDLER(IDM_DESELECT_BY_TYPE, OnEditDeselectByType)
	//view
	COMMAND_RANGE_HANDLER(IDM_VIEW_LARGE_ICONS, IDM_VIEW_DETAILS, OnViewIcon)
	COMMAND_RANGE_HANDLER(IDM_VIEW_ARANGE_BY_NAME, IDM_VIEW_ARANGE_NO_SORT, OnViewArange)
	COMMAND_ID_HANDLER(IDM_OPEN_ROOT_FOLDER, OnViewOpenRootFolder)
	COMMAND_ID_HANDLER(IDM_OPEN_PARENT_FOLDER, OnViewOpenParentFolder)
	COMMAND_ID_HANDLER(IDM_FOLDERS_HISTORY, OnViewOpenFolderHistory)
	COMMAND_ID_HANDLER(IDM_VIEW_REFRESH, OnViewRefresh)
	COMMAND_ID_HANDLER(IDM_VIEW_FLAT_VIEW, OnViewFlat)
	COMMAND_ID_HANDLER(IDM_VIEW_STANDARD_TOOLBAR, OnViewStandardToolbar)
	COMMAND_ID_HANDLER(IDM_VIEW_TOOLBARS_SHOW_BUTTONS_TEXT, OnViewButtonsLables)
	COMMAND_ID_HANDLER(IDM_VIEW_TOOLBARS_LARGE_BUTTONS, OnViewLargeButtons)
	COMMAND_ID_HANDLER(ID_VIEW_RIBBON, OnViewRibbon)
	//Tools
	COMMAND_ID_HANDLER(IDM_OPTIONS, OnToolsOptions)
	COMMAND_ID_HANDLER(IDM_BENCHMARK, OnToolsBenchmark)

	// Help
	COMMAND_ID_HANDLER(IDM_HELP_CONTENTS, OnHelpContent)
	COMMAND_ID_HANDLER(IDM_ABOUT, OnHelpAbout)
	COMMAND_RANGE_HANDLER(IDS_BOOKMARK_GET, IDS_BOOKMARK_GET + 9, OnBookmarkItemGet)
	COMMAND_RANGE_HANDLER(IDS_BOOKMARK_SET, IDS_BOOKMARK_SET + 9, OnBookmarkItemSet)

	//7zip specific calls
	COMMAND_ID_HANDLER(IDM_ADD, OnExecuteCommand)
	COMMAND_ID_HANDLER(IDM_EXTRACT, OnExecuteCommand)
	COMMAND_ID_HANDLER(IDM_TEST, OnExecuteCommand)

	//      CHAIN_MSG_MAP(CUpdateUI<CMainWnd>)
	CHAIN_MSG_MAP(baseFrame)
	//Fix for the 7z context menu handling
	//TODO: replace it
	if(uMsg == WM_COMMAND)
	{
		if (kToolbarStartID <= LOWORD(wParam))
		{
			lResult = 0;
			ExecuteCommand(LOWORD(wParam));
			return TRUE;
		}
		if(OnMenuCommand(this->m_hWnd, LOWORD(wParam)))
		{
			lResult = 0;
			return TRUE;
		}
	}
	END_MSG_MAP()


	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/);
	LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL &bHandled);
	LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/);
	LRESULT OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/);
	LRESULT OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/);

	//File
	LRESULT OnFileOpen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		OpenItem();
		return 0L;
	}

	LRESULT OnFileOpenInside(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		OpenItemInside();
		return 0L;
	}

	LRESULT OnFileOpenOutside(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		OpenItemOutside();
		return 0L;
	}

	LRESULT OnFileEditItem(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		EditItem();
		return 0L;
	}

	LRESULT OnFileRename(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		Rename();
		return 0L;
	}

	LRESULT OnFileCopyTo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		CopyTo();
		return 0L;
	}

	LRESULT OnFileMoveTo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		MoveTo();
		return 0L;
	}

	LRESULT OnFileDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		bool shift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0;
		Delete(!shift);
		return 0L;
	}

	LRESULT OnFileCalculateCrc(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		CalculateCrc();
		return 0L;
	}

	LRESULT OnFileDiff(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		DiffFiles();
		return 0L;
	}

	LRESULT OnFileSplit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		m_wndPanel.SplitSelectedFiles();
		return 0L;
	}

	LRESULT OnFileCombine(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		m_wndPanel.CombineSelectedFiles();
		return 0L;
	}

	LRESULT OnFileProperties(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		Properties();
		return 0L;
	}

	LRESULT OnFileComment(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		Comment();
		return 0L;
	}

	LRESULT OnFileCreateFolder(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		CreateFolder();
		return 0L;
	}

	LRESULT OnFileCreateFile(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		CreateFile();
		return 0L;
	}
	//Edit
	LRESULT OnEditCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		EditCut();
		return 0L;
	}
	LRESULT OnEditCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		EditCopy();
		return 0L;
	}

	LRESULT OnEditPaste(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		EditPaste();
		return 0L;
	}

	LRESULT OnEditSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		SelectAll(true);
		RefreshStatusBar();
		return 0L;
	}

	LRESULT OnEditDeselectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		SelectAll(false);
		RefreshStatusBar();
		return 0L;
	}

	LRESULT OnEditInvertSelection(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		InvertSelection();
		RefreshStatusBar();
		return 0L;
	}

	LRESULT OnEditSelectSpec(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		SelectSpec(true);
		RefreshStatusBar();
		return 0L;
	}

	LRESULT OnEditSelectByType(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		SelectByType(true);
		RefreshStatusBar();
		return 0L;
	}

	LRESULT OnEditDeselectByType(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		SelectByType(false);
		RefreshStatusBar();
		return 0L;
	}

	LRESULT OnViewIcon(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		//  UINT index = wID - IDM_VIEW_LARGE_ICONS;
		// if (index < 4)
		// {
		//  SetListViewMode(index);

		/*
		CMenu menu;
		menu.Attach(::GetSubMenu(::GetMenu(hWnd), kMenuIndex_View));
		menu.CheckRadioItem(IDM_VIEW_LARGE_ICONS, IDM_VIEW_DETAILS,
		    id, MF_BYCOMMAND);
		*/
		//}
		SetListViewMode(wID);
		return 0L;
	}


	LRESULT OnViewArange(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		PROPID prop = kpidNoProperty;
		switch (wID)
		{
			case IDM_VIEW_ARANGE_BY_NAME:
			{
				prop = kpidName;
				break;
			}
			case IDM_VIEW_ARANGE_BY_TYPE:
			{
				prop = kpidExtension;
				break;
			}
			case IDM_VIEW_ARANGE_BY_DATE:
			{
				prop = kpidMTime;
				break;
			}
			case IDM_VIEW_ARANGE_BY_SIZE:
			{
				prop = kpidSize;
				break;
			}
			case IDM_VIEW_ARANGE_NO_SORT:
			{
				prop = kpidNoProperty;
				break;
			}

		}
		SortItemsWithPropID(prop);
		return 0L;
	}

	LRESULT OnViewOpenRootFolder(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		OpenRootFolder();
		return 0L;
	}

	LRESULT OnViewOpenParentFolder(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		OpenParentFolder();
		return 0L;
	}

	LRESULT OnViewOpenFolderHistory(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		FoldersHistory();
		return 0L;
	}

	LRESULT OnViewRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		RefreshView();
		return 0L;
	}

	LRESULT OnViewFlat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		ChangeFlatMode();
		return 0L;
	}


	LRESULT OnViewStandardToolbar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		SwitchStandardToolbar();
		return 0L;
	}

	LRESULT OnViewArchiveToolbar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		SwitchStandardToolbar();
		return 0L;
	}

	LRESULT OnViewButtonsLables(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		SwitchButtonsLables();
		return 0L;
	}

	LRESULT OnViewLargeButtons(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		SwitchLargeButtons();
		return 0L;
	}

	LRESULT OnViewRibbon(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		ShowRibbonUI(!IsRibbonUI());
		UISetCheck(ID_VIEW_RIBBON, IsRibbonUI());
		return 0L;
	}

	LRESULT OnToolsOptions(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		OptionsDialog(m_hWnd);
		return 0L;
	}

	LRESULT OnToolsBenchmark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		CPanel::CDisableTimerProcessing disableTimerProcessing1(m_wndPanel);
		Common::Archive::Benchmark();
		return 0L;
	}

	LRESULT OnHelpContent(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		ShowHelpWindow(NULL, kFMHelpTopic);
		return 0L;
	}

	LRESULT OnHelpAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		CAboutDialog dialog;
		dialog.DoModal();
		return 0L;
	}

	LRESULT OnBookmarkItemGet(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		OpenBookmark(wID - IDS_BOOKMARK_GET);
		return 0L;
	}

	LRESULT OnBookmarkItemSet(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		OpenBookmark(wID - IDS_BOOKMARK_SET);
		return 0L;
	}

	LRESULT OnMenuPopup(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/)
	{
		OnMenuActivating(m_hWnd, HMENU(wParam), LOWORD(lParam));
		return 0L;
	}

	LRESULT OnSetFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
	{
		SetFocusToLastItem();
		return 0L;
	}

	LRESULT OnExecuteCommand(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
	{
		ExecuteCommand(wID);
		return 0L;
	}

};

#endif
